package filemanager;

import filesystem.FileNode;

import javax.swing.*;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreePath;

public class CopyOperation {
    public static void performCopy(JTree tree, DefaultTreeModel model, JFrame frame) {
        TreePath selectedPath = tree.getSelectionPath();
        if (selectedPath == null) {
            JOptionPane.showMessageDialog(frame, "请先选中一个节点");
            return;
        }

        FileNode selectedNode = (FileNode) selectedPath.getLastPathComponent();

        String newName = JOptionPane.showInputDialog(frame, "请输入复制品的名称：");
        if (newName == null || newName.trim().isEmpty()) return;

        FileNode copyNode = new FileNode(newName, selectedNode.isDirectory());

        FileNode parent = (FileNode) selectedNode.getParent();
        if (parent != null) {
            parent.add(copyNode);
            model.reload(parent);
        }
    }
}
